/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utility;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


/**
 *
 * @author Dom
 */
public class ConnectDB {

   public static Connection GetConnection()
   {
       try
       {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection connect = DriverManager.getConnection("jdbc:odbc:QLOT");
           return connect;
       }
       catch(Exception ex)
       {
           ex.printStackTrace();
           return null;
       }
   }
   //Dùng để cập nhật, thêm, xóa
   public static int ExecuteQueryString(String sql)     
   {
       try
       {
           Statement st = GetConnection().createStatement();
           return st.executeUpdate(sql);
           //Trả về số dòng update
       }
       catch(Exception ex)
       {
           ex.printStackTrace();
       }
       return -1;
   }
   
   //Dùng để lấy bảng
   public static ResultSet getResultSet(String sql)     
   {
       try
       {
           Statement st = GetConnection().createStatement();
           ResultSet rs = st.executeQuery(sql);
           return rs;
       }
       catch(Exception ex)
       {
           ex.printStackTrace();
           return null;
       }
   }
    
}
